﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR96ResponseV1", Namespace="http://kis.x-road.eu/", Target=typeof(RR96ResponseV1))]
    public class RR96ResponseV1Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected RR96ResponseV1 clazz;
        
        public RR96ResponseV1Serializer(RR96ResponseV1 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Veakood");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Isikuandmed");
            if (clazz.Isikuandmed!=null) {
                for (int x = 0; ((clazz.Isikuandmed != null) 
                            && (x < clazz.Isikuandmed.Count)); x = (x + 1)) {
                    if (clazz.Isikuandmed[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData(clazz.Isikuandmed[x]);
                        if (ShouldWriteTypeAttribute(typeof(RR96ResponseV1.IsikuandmedType), clazz.Isikuandmed[x].GetType())) {
                            Writer.WriteTypeAttribute(metaIsikuandmed.TypeQualifiedName.Namespace, metaIsikuandmed.TypeQualifiedName.Name);
                        }
                        var isikuandmedSerializer = metaIsikuandmed.NewSerializer(clazz.Isikuandmed[x]);
                        isikuandmedSerializer.WriteXmlAttributes(Writer);
                        isikuandmedSerializer.WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikuandmed");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "Veakood")) {
                goto Veakood;
            }
            else {
                if ((Reader.LocalName == "Veatekst")) {
                    goto Veatekst;
                }
                else {
                    if ((Reader.LocalName == "Isikuandmed")) {
                        goto Isikuandmed;
                    }
                    else {
                        return;
                    }
                }
            }
        Veakood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR96ResponseV1>Veakood");
            }
            clazz.Veakood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("Veakood")).Value;
            goto START;
        Veatekst:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR96ResponseV1>Veatekst");
            }
            clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Veatekst")).Value;
            goto START;
        Isikuandmed:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR96ResponseV1>Isikuandmed");
            }
            clazz.Isikuandmed = new System.Collections.Generic.List<RR96ResponseV1.IsikuandmedType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("Isikuandmed");
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR96ResponseV1>Isikuandmed>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData<RR96ResponseV1.IsikuandmedType>(Reader, ">>>RR96ResponseV1>Isikuandmed>item", "http://kis.x-road.eu/");
                    RR96ResponseV1.IsikuandmedType item = metaIsikuandmed.NewEntity<RR96ResponseV1.IsikuandmedType>();
                    clazz.Isikuandmed.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        var isikuandmedSerializer = metaIsikuandmed.NewSerializer(item);
                        isikuandmedSerializer.ReadXmlAttributes(Reader);
                        Reader.ReadStartElement("item");
                        isikuandmedSerializer.ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR96ResponseV1>Isikuandmed>item", Namespace="http://kis.x-road.eu/", Target=typeof(RR96ResponseV1.IsikuandmedType))]
        public class IsikuandmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR96ResponseV1.IsikuandmedType clazz;
            
            public IsikuandmedTypeSerializer(RR96ResponseV1.IsikuandmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXmlAttributes(Writer);
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isikuandmed.Isikukood");
                if (clazz.IsikuandmedIsikukood!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Eesnimi");
                if (clazz.IsikuandmedEesnimi!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Meesnm");
                if (clazz.IsikuandmedMeesnm!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedMeesnm))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedMeesnm");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXmlAttributes(Reader);
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
            START:
                if ((Reader.LocalName == "Isikuandmed.Isikukood")) {
                    goto IsikuandmedIsikukood;
                }
                else {
                    if ((Reader.LocalName == "Isikuandmed.Eesnimi")) {
                        goto IsikuandmedEesnimi;
                    }
                    else {
                        if ((Reader.LocalName == "Isikuandmed.Meesnm")) {
                            goto IsikuandmedMeesnm;
                        }
                        else {
                            return;
                        }
                    }
                }
            IsikuandmedIsikukood:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR96ResponseV1>Isikuandmed>item>Isikuandmed.Isikukood");
                }
                clazz.IsikuandmedIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Isikukood")).Value;
                goto START;
            IsikuandmedEesnimi:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR96ResponseV1>Isikuandmed>item>Isikuandmed.Eesnimi");
                }
                clazz.IsikuandmedEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Eesnimi")).Value;
                goto START;
            IsikuandmedMeesnm:
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR96ResponseV1>Isikuandmed>item>Isikuandmed.Meesnm");
                }
                clazz.IsikuandmedMeesnm = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Meesnm")).Value;
                goto START;
            }
        }
    }
}
